import { ORDER_GET_LIST, ORDER_CHANGE_FILTER } from '../action-types'

import factory from './initial-state'

const typesCommands = {
    [ORDER_GET_LIST](state, action) {
        return Object.assign({}, state, {
            orderList: action.res.result.list,
            orderTotalCount: action.res.result.count
        })
    },
    [ORDER_CHANGE_FILTER](state, action) {
        return Object.assign({}, state, {...action.filter })
    }
}

export default function(state = factory(), action) {
    const actionResponse = typesCommands[action.type]
    return actionResponse ? actionResponse(state, action) : state
}